package com.t3go.t3_map.utils;

import android.graphics.Color;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.widget.TextView;

import com.t3go.t3_map.entity.FontWeight;
import com.t3go.t3_map.entity.NormalStyle;
import com.t3go.t3_map.entity.TextBean;


public class StyleUtils {

    public static void setTextStyle(TextView textView, TextBean data) {
        if (textView == null || data == null) {
            return;
        }
        textView.setText(data.getText());

        NormalStyle style = data.getNormalStyle();
        if (style != null) {
            if (style.getFontSize() > 0) {
                textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, style.getFontSize());
            }

            Integer color = parseColor(style.getColor());
            if (color != null) {
                textView.setTextColor(color);
            }

            if (FontWeight.BOLD.equalsIgnoreCase(style.getFontWeight())) {
                textView.setTypeface(Typeface.DEFAULT_BOLD);
            } else if (FontWeight.MEDIUM.equalsIgnoreCase(style.getFontWeight())) {
                textView.setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
            } else {
                textView.setTypeface(Typeface.DEFAULT);
            }
        }
    }


    public static Integer parseColor(String value) {
        try {
            return Color.parseColor(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
